<template>
    <div class="page-container">
        <div>
            <div class="operation-container">
                <el-button type="primary" @click="onPrint">打印</el-button>
            </div>
            <div id="deviceDispatchPrint" class="print-container">
                <div class="print-title">发票申请单</div>
                <table class="table-class" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="print-label">项目编码</td>
                        <td class="print-input-content2">
                            {{ form.projectCode }}
                        </td>
                        <td class="print-label">项目名称</td>
                        <td class="print-input-content2">
                            {{ form.projectName }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">开票日期</td>
                        <td class="print-input-content2">
                            {{ formatUtil.dateFormat(form.createTime) }}
                        </td>
                        <td class="print-label">开票金额(元)</td>
                        <td class="print-input-content2">
                            {{ form.fapiaoAmount == null ? '' : form.fapiaoAmount / 100 }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">预计到账时间</td>
                        <td class="print-input-content2">
                            {{ formatUtil.dateFormat(form.expectedArrivalTime) }}
                        </td>
                        <td class="print-label">业主单位</td>
                        <td class="print-input-content2">
                            {{ form.clientCompanyName }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">发票摘要</td>
                        <td class="print-input-content2">
                            {{ form.fapiaoAbsrtact }}
                        </td>
                        <td class="print-label">是否开具收据</td>
                        <td class="print-input-content2">
                            {{ form.needReceipt == 1 ? '是' : '否' }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">发票备注</td>
                        <td class="print-input-content" colspan="3">
                            {{ form.fapiaoRemark }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">付款单位名称</td>
                        <td class="print-input-content2">
                            {{ form.payer }}
                        </td>
                        <td class="print-label">纳税人识别号</td>
                        <td class="print-input-content2">
                            {{ form.payerTaxIdNo }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">地址</td>
                        <td class="print-input-content2">
                            {{ form.payerAddress }}
                        </td>
                        <td class="print-label">开户行</td>
                        <td class="print-input-content2">
                            {{ form.payerBankName }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">账号</td>
                        <td class="print-input-content2">
                            {{ form.payerBankNo }}
                        </td>
                        <td class="print-label">电话</td>
                        <td class="print-input-content2">
                            {{ form.payerTelphone }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label-line" colspan="4">审批信息</td>
                    </tr>
                    <tr>
                        <td class="print-table-line" colspan="4">
                            <PrintFlowHistoryCpt :taskId="id"></PrintFlowHistoryCpt>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</template>
<script>
import { ref, toRefs, reactive, onMounted } from 'vue'
import { ElNotification } from 'element-plus'
import http from '@/http.js'
import printJS from 'print-js'
import formatUtil from '@/utils/format.js'
import PrintFlowHistoryCpt from '../components/PrintFlowHistoryCpt.vue'

export default {
    props: {
        id: {
            type: String,
            default: ''
        }
    },
    components: {
        PrintFlowHistoryCpt
    },
    setup(props, ctx) {
        const state = reactive({
            form: {},
            flowList: []
        })

        const loadDetail = () => {
            http.fetchForm({
                url: '/yunying/fapiao/findById',
                data: {
                    id: props.id
                }
            }).then((res) => {
                let data = res.data
                state.form = data
            })
        }

        const onPrint = () => {
            printJS({
                printable: 'deviceDispatchPrint',
                type: 'html',
                targetStyles: ['*'],
                style: '@page{margin-top: 1mm;margin-bottom: 1mm;}'
            })
        }

        onMounted(() => {
            loadDetail()
        })

        return {
            formatUtil,
            ...toRefs(state),
            onPrint
        }
    }
}
</script>
<style scoped>
@import '@/assets/css/print.css';
</style>
